$(function(){
	// Download by http://www.codefans.net
	$('#keyboard li').click(function(){
		var $this = $(this),
			character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
	var $write = $(this).parent("ul").siblings("input");
	var	shift = false;
	var	capslock = false;
		// Shift keys
		if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
			$('.letter').toggleClass('uppercase');
			$('.symbol span').toggle();
			
			shift = (shift === true) ? false : true;
			capslock = false;
			return false;
		}
		
		// Caps lock
		if ($this.hasClass('capslock')) {
			$('.letter').toggleClass('uppercase');
			capslock = true;
			return false;
		}
		
		// Delete
		if ($this.hasClass('delete')) {
			var html = $write.val();
			
			$write.val(html.substr(0, html.length - 1));
			$('.printbtn').addClass('noprintbtn').removeClass('pulse');
			return false;
		}
		
		// Special characters
		if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
		if ($this.hasClass('space')) character = ' ';
		if ($this.hasClass('tab')) character = "\t";
		if ($this.hasClass('return')) character = "\n";
		
		// Uppercase letter
		if ($this.hasClass('uppercase')) character = character.toUpperCase();
		
		// Remove shift once a key is clicked.
		if (shift === true) {
			$('.symbol span').toggle();
			if (capslock === false) $('.letter').toggleClass('uppercase');
			
			shift = false;
		}
		
		// Add the character
//		$write.css("background","#000000");
		
		$write.val($write.val() + character);
		if ($write.val().length==18) {
			$(".cover").show();
			if ($write.val()=="222222222222222222") {
				$(".cover").hide();
				checksuces($write);
			} else{
				$(".cover").hide();
				swal({
					title: "WrongID",
					type: 'error',
					background: '#fff',
					allowOutsideClick: false,
					showConfirmButton: false,
					timer: 1200
				}).then(
					function () {},
					function(dismiss){
				});
			}
		} else if($write.val().length>18){
			var tval = $write.val();
				tval = tval.substring(0,18);
			$($write).val(tval);
		} else{
			$('.printbtn').addClass('noprintbtn').removeClass('pulse');
		};
	});
});